package com.ylt.callable;

import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        new Thread(new MyThread()).start();
//        new Thread(new Runnable()).start();
//        new Thread(new FutureTask<V>()).start();

        //启动Callable
//        new Thread(new FutureTask<>(new MyThread1()),"A").start();
        MyThread1 myThread1 = new MyThread1();
        FutureTask vFutureTask = new FutureTask(myThread1);//适配器
        new Thread(vFutureTask,"A").start();
        Integer o =(Integer) vFutureTask.get();//返回结果
        System.out.println(o);

    }
}

class MyThread implements Runnable{
    @Override
    public void run() {

    }
}

class MyThread1 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("call()");
        return 123;
    }
}
